<template>
	<view class="allQuestion">
			<!-- 第一张图-->
			<swiper :interval="1000" :duration="500" :current="curr_index" :disable-touch="true">
				<swiper-item class="questionOne" v-for="(item,index1) in testlist" :key="index1">
						<view class="questionOne-cont">
							<text class="questionOne-cont-tex">NO.{{index1+1}}</text>
							<view class="questionOne-cont-top">
								<view class="questionOne-cont-top-text">
									<text>{{item.topics}}</text> 
								</view>
							</view>
							<!-- 选项 -->
							<view class="questionOne-cont-chose" v-for="(an,index2) in item.options" :key="index2">
								<view class="questionOne-cont-chose-answer" ref="dataVal" @click="chose(index1,index2)">
									<button>{{an}}</button>
								</view>
							</view>
						</view>
				</swiper-item>
			</swiper>
	</view>

</template>

<script>
	export default {
			data() {
				return {
					testlist:{},
					updata:{
						uuid:"",
						list:[]
					},
					uuid: "",
					index: '',
					curr_index: 0,
					paramVal: [],
					obj: {},
					ans: '',
				}
			},
			onLoad(options) {
				// console.log("dotest-options",options)
				this.uuid = options.uuid;
				this.index = options.index
				// console.log("dotest-index",this.index)
				this.getTestlist()
			},
			methods: {
				async getTestlist(){
					let res = await this.$store.dispatch("getTestList",this.uuid);
					if(res=="ok"){
						this.testlist = this.$store.state.test.testlist;
						console.log("this.testlist",this.testlist);
						console.log(this.testlist.length)
					}
				},
				chose(index1,index2){
					let uuid = this.testlist[index1].uuid;
					let option = this.testlist[index1].options[index2];
					console.log(index1,index2);
					console.log(uuid,option);
					this.updata.list.push({option,uuid});
					let curr_index = this.curr_index;
					if(curr_index < this.testlist.length){
						curr_index+=1;
					}
					this.curr_index = curr_index;
					if (this.curr_index === this.testlist.length) {
						this.updata.uuid = this.uuid;
						console.log(this.updata);
						this.upTestans();
					}
				},
				async upTestans(){
					let res = await this.$store.dispatch("upTestAns",this.updata);
					setTimeout(function(){
						uni.showLoading({
							title: "查询结果中..."
						})
					},200)
					if(res.msg=="答题成功"){
						setTimeout(() => {
								uni.hideLoading()
						}, 300)
						uni.navigateTo({
							url: '/pages/Grades/index?score='+res.score+'&index='+this.index ,
						})
					}
				}
			}
		}

</script>

<style lang="scss" scoped>
	.allQuestion {
		>swiper {
			height: 95.8vh !important;
			border: 2px solid #fc86c2;
			width: 90%;
			margin-left: 35upx;
			margin-top: 10upx;
			box-shadow:5px 5px 1px #fc86c2;
			border-radius: 20upx;
		}
	}

	.questionOne {
		&-cont {
			padding: 78upx 60upx 0 70upx;
			height: 94vh;
			&-pic {
				margin-bottom: 8upx;

				>image {
					width: 158upx;
					height: 92upx;
				}
			}
			&-tex {
				font-size: 60upx;
				font-weight: 600;
				color: #935217;
				font-style: italic;
			}

			&-top {
				padding-left: 2upx;

				&-text {
					width: 666upx;
					font-size: 44upx;
					font-weight: 600;
					color: #935217;
					line-height: 60upx;

					>text {
						box-shadow: 0 -7px #ffe26c inset;
					}
				}
			}

			&-chose:nth-child(2) {
				padding-top: 10upx;
			}
		}
	}
	page {
		font-family: PingFangSC, PingFangSC-Semibold;
	}
	.questionOne-cont {
		padding: 78upx 60upx 0 70upx;
	}
	.questionOne-cont-pic {
		margin-bottom: 8upx;
		> image {
			width: 158upx;
			height: 92upx;
		}
	}
	.questionOne-cont-chose {
		padding-top: 30upx;
	}
	.questionOne-cont-chose-answer {
		> button {
			height: 110upx;
			font-size: 35upx;
			font-weight: 600;
			color: #955217;
			background-color: #c7c7ed;
			line-height: 120upx;
			margin-top: 5upx;
			box-shadow: 5px 5px 1px #7b79dc;
			border: none;
			border-radius: 40upx;
		}
	}

</style>

